<?php
if( !defined('IN') ) die('bad request');
include_once( AROOT . 'lib' . DS . 'mycurl.class.php' );

Class edudata
{
	public $mycurl;
	/**
	 * teacher email
	 * Need For Login
	 */
	public $teacher_email;
	/**
	 * teacher email
	 * Need For Login
	 */
	public $teacher_pwd;
	/**
	 * teacher level
	 * xm
	 */
	public $teacher_level;
	/**
	 * @ignore
	 */
	public function authorizeURL()  { return c('authorizeURL'); }
	public function tokenURL()  { return c('tokenURL'); }


	function __construct( $teacher_email = NULL, $teacher_pwd = NULL ) {
		$this->teacher_email = $teacher_email;
		$this->teacher_pwd = $teacher_pwd;
		$this->client_name = c('client_name');

		$this->mycurl = new mycurl();
	}
	
	public function refresh_client_access_token()
	{
		$access_token=$_COOKIE['atk'];
		//setCOOKIE('atk',$access_token,time()+$expires_in-200);
		if($access_token=="" || is_null($access_token)){

			$result=self::get_client_access_token();
			if($result['access_token']!==NULL)
			{
				$access_token=$result['access_token'];
				$expires_in=$result['expires_in'];
				setCOOKIE('atk',$access_token,time()+$expires_in-1000);
			}
		}
		return $access_token;
	}

	function get_client_access_token()
	{
		//grant_type:client_credentials
		$params = Array();
		$params['client_id']=c("client_id");
		$params['client_secret']=c("client_secret");
		$params['grant_type']="client_credentials";

		$result = $this->mycurl->post(c('tokenURL'),$params);
		return $result;
	}

	//特定user的access token
	function get_user_access_token()
	{
		//如果access token过期
		if(IS_NULL($_COOKIE['atk'.$_SESSION['teacher']['teacher_id']]) || !isset($_COOKIE['atk'.$_SESSION['teacher']['teacher_id']]))
		{
			//待处理
			
		}else{
			$access_token=$_COOKIE['atk'.$_SESSION['teacher']['teacher_id']];
			return $access_token;
		}
	
	}

	function verify()
	{
		$url = "teacher/verify/";
		$access_token=self::refresh_client_access_token();
		$params = array();
		$params['email'] = $this->teacher_email;

		$params['access_token']=$access_token;
		//注意密码这里需要md5（也许能增强安全，再加上https）
		$params['teacher_pwd'] = md5( $this->teacher_pwd );

		//在这client（即项目管理子系统）的name
		$params['client_name'] = c('client_name');

		$result = $this->mycurl->post($url,$params);
		return $result;
	}

	function fund_sign_verify($email,$pwd)
	{
		$url = "teacher/verify/";
		$access_token=self::refresh_client_access_token();
		$params = array();
		$params['email'] = $email;

		$params['access_token']=$access_token;
		//注意密码这里需要md5（也许能增强安全，再加上https）
		$params['teacher_pwd'] = md5( $pwd );

		//在这client（即项目管理子系统）的name
		$params['client_name'] = c('client_name');

		$result = $this->mycurl->post($url,$params);
		return $result;
	}

	function general_data()
	{
		//注册用户时需要
		//注册使用的access_token无user_id
		$url = "general/get/";
		$access_token=self::refresh_client_access_token();
		$params = Array();

		$params['access_token']=$access_token;

		$result = $this->mycurl->post($url,$params);
		return $result;
	}
	
	function add_teacher($teacher_infos)
	{
		$url = "odp_teacher/insert/";
		$access_token = self::refresh_client_access_token();
		$params=$teacher_infos;
		$params['access_token'] = $access_token;
				
		$result = $this->mycurl->post($url,$params);
		return $result;

	}

	function has_email($email)
	{
		$url = "odp_teacher/list/";
		$access_token = self::refresh_client_access_token();
		$params=Array();
		$params['access_token'] = $access_token;
		$params['email'] = $email;
		$result = $this->mycurl->post($url,$params);

		if($result['err_code']=='0')
			return ($result['data']==false)?false:$result['data']['items'][0];
	}

	function has_mobile_phone($mobile_phone)
	{
		$url = "odp_teacher/list/";
		$access_token = self::refresh_client_access_token();
		$params=Array();
		$params['access_token'] = $access_token;
		$params['mobile_phone'] = encrypt($mobile_phone,c('key'));

		$result = $this->mycurl->post($url,$params);
		if($result['err_code']=='0')
			return ($result['data']==false)?false:true;
	}

	function verify_email($code,$token)
	{
		$url="odp_teacher/list/";
		$params=Array();
		$params['access_token']=$token;
		$params['email_verificaion_code']=$code;

		$result=$this->mycurl->post($url,$params);

		if($result['err_code']=='0' && $result['data']['items'][0]['is_email_verified']=='0')
		{
			$url="odp_teacher/update/";
			$teacher_id=$result['data']['items'][0]['teacher_id'];
			$arr=Array();
			//重新获取，防止过期
			$arr['access_token']=self::refresh_client_access_token();
			$arr['is_email_verified']=1;
			$arr['teacher_id']=$teacher_id;

			$result_update=$this->mycurl->post($url,$arr);

			if($result_update['err_code']=='0') 
				return (self::update_kvdb_status($email))?1:0;

		}else if($result['err_code']=='0' && $result['data']['items'][0]['is_email_verified']=='1')
		{
			return 2;
		}

		if($result['err_code']=='10001') return 3;
	}

	function update_verify_code($email,$code,$teacher_id)
	{
		$url="odp_teacher/update/";
		$params=Array();
		$params['email_verificaion_code']=$code;
		$params['teacher_id']=$teacher_id;

		$params['access_token']=self::refresh_client_access_token();

		$result=$this->mycurl->post($url,$params);

		if($result['err_code']=='0'){
			//更新数据后，设置缓存需要更新
			$status=self::update_kvdb_status($email);
			return ($status)?true:false;
		}
	}

	//设置email teacher的kvdb状态，使下次取出数据时重新从Mysql取出
	function update_kvdb_status($email)
	{
		$url_rekset="odp_teacher/rekset/";
		$arr=Array();
		$arr['access_token']=self::refresh_client_access_token();

		$arr['email']=$email;
		$result=$this->mycurl->post($url_rekset,$arr);

		return ($result['err_code']=='0')?True:False;
	}

	/******************************************
	*质量工程参数 字段名限制，只能修改value，采用了序列化存储，取出后逆序列化使用
	*
	*项目类别 qlty_category : qlty_project_category,qlty_course_category,qlty_team_category
	*项目级别 qlty_rank
	*所属科类 qlty_specity
	******************************************/
	function get_qlty_option()
	{
		$url="qlty_option/list/";
		$access_token = self::get_user_access_token();
		$params=Array();
		$params['access_token'] = $access_token;

		$result=$this->mycurl->post($url,$params);

		return ($result['err_code']=='0')?($result['data']['items']):FALSE;

	}

	
	//Add quality Project
	function add_qlty_project($params)
	{
		$url="qlty_project/insert/";
		$access_token = self::get_user_access_token();

		$params = $params + Array('access_token'=>$access_token);

		$result = $this->mycurl->post($url,$params);
		//print_r($result);exit();
		return ($result['err_code']=='0')?$result['data'][0]['qlty_project_id']:false;

	}
	
	function add_qlty_project_asset($params)
	{
		$url="qlty_asset/insert/";
		$access_token = self::get_user_access_token();
		$params = $params + Array('access_token'=>$access_token);
		$result = $this->mycurl->post($url,$params);

		return ($result['err_code']=='0')?$result['data'][0]['asset_id']:false;
	}

	function get_qlty_asset_status($pid,$tid)
	{
		$url="qlty_asset/status/";
		$access_token = self::get_user_access_token();
		$params = Array(
			'access_token'=>$access_token,
			'pid'=>$pid,
			'tid'=>$tid
		);
		$result = $this->mycurl->post($url,$params);
		return ($result['err_code']=='0')?$result['data']:false;
	}

	function update_pwd($newpwd,$oldpwd,$tid)
	{
		$url="odp_teacher/update/";

		if( (md5($oldpwd)) != $_SESSION['teacher']['teacher_pwd'] ){
			return 'invalidpwd';
		}else{
			$access_token = self::get_user_access_token();
			$params = Array(
				'access_token'=>$access_token,
				'teacher_pwd'=>md5($newpwd),
				'teacher_id'=>$tid
			);
			$status = $this->mycurl->post($url,$params);
			if($status['err_code']=='0'){
				//需要更新teacher的缓存
				return self::update_kvdb_status($_SESSION['teacher']['email']);
			}
		}
	}

	function get_user_projects($tid)
	{
		$url="qlty_project/list/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'director_id'=>$tid	
		);
		$results=$this->mycurl->post($url,$params);

		if($results['err_code']=='0')
		{
			return $results['data']['items'];
		}

	}

	function get_project_participants($project_id)
	{
		$url="project/participants/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'project_id'=>$project_id	
		);
		$results=$this->mycurl->post($url,$params);

		if($results['err_code']=='0')
		{
			return $results['data'];
		}
	}

	function update_qlty_option($key,$value)
	{
		$url="qlty_option/update/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'qlty_option_name'=>$key,
			'qlty_option_value'=>$value
		);
		$results=$this->mycurl->post($url,$params);

		if($results['err_code']=='0')
			return $results['data'][0]['qlty_option_id'];
	}

	function update_project_participants($project_id,$participants)
	{
		$url="participants/change/";
		$access_token = self::get_user_access_token();

		$params=Array(
			'access_token'=>$access_token,
			'project_id'=>$project_id,
			'participants'=>serialize($participants)
		);

		$results=$this->mycurl->post($url,$params);
		return $results;
	
	}

	function update_project_status($project_id,$tid,$status)
	{
		$url="qlty_project/update/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'qlty_project_id'=>$project_id,
			'director_id'=>$tid,
			'status'=>$status
		);

		$results=$this->mycurl->post($url,$params);
		if($results['err_code']=='0')
			return $results['data'];
	}

	function update_project_apply_time($project_id,$tid)
	{
		$url="qlty_project/update/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'qlty_project_id'=>$project_id,
			'director_id'=>$tid,
			'apply_time'=>time()
		);

		$results=$this->mycurl->post($url,$params);
		if($results['err_code']=='0')
			return $results['data'];
	}

	function update_project_apply_established_time($project_id,$tid)
	{
		$url="qlty_project/update/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'qlty_project_id'=>$project_id,
			'director_id'=>$tid,
			'apply_time'=>time(),
			'established_time'=>time()
		);

		$results=$this->mycurl->post($url,$params);
		if($results['err_code']=='0')
			return $results['data'];
	}

	function update_project_done_time($project_id,$tid)
	{
		$url="qlty_project/update/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'qlty_project_id'=>$project_id,
			'director_id'=>$tid,
			'done_time'=>time()
		);

		$results=$this->mycurl->post($url,$params);
		if($results['err_code']=='0')
			return $results['data'];
	}

	function get_wait_for_trial_projects($status)
	{
		$url="qlty_project/this_status/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'status'=>$status
		);
		$results=$this->mycurl->post($url,$params);
		if($results['err_code']=='0')
			return $results['data'];
	}

	function get_wait_for_trial_department_projects($status,$department_id)
	{
		$url="qlty_project/department_this_status/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'status'=>$status,
			'department_id'=>$department_id
		);
		$results=$this->mycurl->post($url,$params);
		if($results['err_code']=='0')
			return $results['data'];
	}

	function get_project_detail_by_id($project_id,$teacher_id)
	{
		$url="qlty_project/list/";
		//check qrcode need this api, so use client access token
		$access_token = self::refresh_client_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'qlty_project_id'=>$project_id,
			'director_id'=>$teacher_id
		);
		$results=$this->mycurl->post($url,$params);

		if($results['err_code']=='0')
			return $results['data']['items'][0];
	}

	function get_project_detail_with_project_id($project_id)
	{
		$url="qlty_project/list/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'qlty_project_id'=>$project_id
		);
		$results=$this->mycurl->post($url,$params);

		if($results['err_code']=='0')
			return $results['data']['items'][0];
	}

	function get_project_assets($project_id)
	{
		$url="qlty_asset/list/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'qlty_project_id'=>$project_id
		);
		$results=$this->mycurl->post($url,$params);
		if($results['err_code']=='0')
			return $results['data']['items'];
	}

	function get_project_assets_with_type($project_id,$asset_type)
	{
		$url="qlty_asset/list/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'qlty_project_id'=>$project_id,
			'asset_type'=>$asset_type
		);
		$results=$this->mycurl->post($url,$params);
		if($results['err_code']=='0')
			return $results['data']['items'];
	}

	function get_all_projects_assets()
	{
		$url="qlty_asset/list/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token
		);
		$results=$this->mycurl->post($url,$params);
		if($results['err_code']=='0')
			return $results['data']['items'];
	}

	function get_director_detail($teacher_id)
	{
		$url="odp_teacher/teacher_detail/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'teacher_id'=>$teacher_id
		);
		$results=$this->mycurl->post($url,$params);
		if($results['err_code']=='0')
			return $results['data'];
	
	}

	function delete_asset_by_id($asset_id)
	{
		$url="qlty_asset/remove/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'asset_id'=>$asset_id
		);
		$results=$this->mycurl->post($url,$params);
		if($results['err_code']=='0')
			return $results['data'];
	}

	function update_qlty_project($params)
	{
		$url="qlty_project/update/";
		$access_token = self::get_user_access_token();
		$params = $params + Array('access_token'=>$access_token);
		$results=$this->mycurl->post($url,$params);
		if($results['err_code']=='0')
			return $results['data'];
	}

	function update_odp_teacher($params)
	{
		$url="odp_teacher/update/";
		$access_token = self::refresh_client_access_token();
		$params = $params + Array('access_token'=>$access_token);
		$results=$this->mycurl->post($url,$params);
		if($results['err_code']=='0')
			return $results['data'];
	}

	function add_review($review_name,$start_time,$end_time,$status,$project_type)
	{
		$url="rev_review/insert/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'review_name'=>$review_name,
			'start_time'=>$start_time,
			'end_time'=>$end_time,
			'status_num'=>$status,
			'project_type'=>$project_type
		);
		$results=$this->mycurl->post($url,$params);

		if($results['err_code']=='0')
			return $results['data']['0']['review_id'];
	
	}

	function get_all_reviews()
	{
		$url="rev_review/list/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token
		);
		$results=$this->mycurl->post($url,$params);
		if($results['err_code']=='0')
			return $results['data']['items'];
	}

	function get_review_by_id($review_id)
	{
		$url="rev_review/list/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'review_id'=>$review_id
		);
		$results=$this->mycurl->post($url,$params);
		if($results['err_code']=='0')
			return $results['data']['items'][0];
	}

	function update_review($review_id,$review_name,$start_time,$end_time,$status)
	{
		$url="rev_review/update/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'review_id'=>$review_id,
			'review_name'=>$review_name,
			'start_time'=>$start_time,
			'end_time'=>$end_time,
			'status_num'=>$status
		);
		$results=$this->mycurl->post($url,$params);

		if($results['err_code']=='0')
			return $results['data'][0];
	}

	function update_review_template($review_id,$template_id)
	{
		$url="rev_review/update/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'review_id'=>$review_id,
			'template_id'=>$template_id
		);
		$results=$this->mycurl->post($url,$params);

		if($results['err_code']=='0')
			return $results['data'][0];
	}

	function delete_review($review_id)
	{
		$url="/rev_review/remove/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'review_id'=>$review_id
		);
		$results=$this->mycurl->post($url,$params);
		if($results['err_code']=='0')
			return $results['data']['msg'];
	}

	function add_group($review_id,$group_name)
	{
		$url="rev_group/insert/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'review_id'=>$review_id,
			'group_name'=>$group_name
		);
		$results=$this->mycurl->post($url,$params);
		if($results['err_code']=='0')
			return $results['data'][0];
	}

	function get_review_all_groups($review_id)
	{
		$url="rev_group/list/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'review_id'=>$review_id
		);
		$results=$this->mycurl->post($url,$params);
		if($results['err_code']=='0')
			return $results['data']['items'];
	}

	function delete_group($group_id)
	{
		$url="rev_group/remove/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'group_id'=>$group_id
		);
		$results=$this->mycurl->post($url,$params);
		if($results['err_code']=='0')
			return true;
	}

	function get_group_by_id($group_id,$review_id)
	{
		$url="rev_group/list/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'group_id'=>$group_id,
			'review_id'=>$review_id

		);
		$results=$this->mycurl->post($url,$params);
		
		if($results['err_code']=='0')
			return $results['data']['items'][0];

	}

	function update_group_by_id($group_id,$review_id,$group_name)
	{
		$url="rev_group/update/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'group_id'=>$group_id,
			'review_id'=>$review_id,
			'group_name'=>$group_name

		);
		$results=$this->mycurl->post($url,$params);
		
		if($results['err_code']=='0')
			return $results['data'];
	}

	function get_teachers_with_level($level,$review_id)
	{
		$url="odp_teacher/level/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'level'=>$level,
			'review_id'=>$review_id
		);
		
		$results=$this->mycurl->post($url,$params);
		//print_r($results);exit();
		if($results['err_code']=='0')
			return $results['data'];
		
	}

	function update_experts_group_re($group_id,$experts_arr)
	{
		$url="rev_expert_group_re/replaceinto/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'group_id'=>$group_id,
			'experts_arr'=>$experts_arr
		);

		$results=$this->mycurl->post($url,$params);
		if($results['err_code']=='0')
			return $results['data'];
	}

	function get_projects_detail_with_status_review($review_id,$status,$project_type)
	{
		$url="rev_project_group_re/projects_status_review/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'review_id'=>$review_id,
			'status'=>$status,
			'project_type'=>$project_type
		);

		$results=$this->mycurl->post($url,$params);
		if($results['err_code']=='0')
			return $results['data'];

	}

	function update_project_group_re($group_id,$projects_arr)
	{
		$url="rev_project_group_re/replaceinto/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'group_id'=>$group_id,
			'projects_arr'=>$projects_arr
		);

		$results=$this->mycurl->post($url,$params);
		//print_r($results);exit();
		if($results['err_code']=='0')
			return $results['data'];
	}

	function add_template($template_name)
	{
		$url="/rev_template/insert/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'template_name'=>$template_name
		);

		$results=$this->mycurl->post($url,$params);
		if($results['err_code']=='0')
			return $results['data'];
	}

	function get_all_template()
	{
		$url="/rev_template/list/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token
		);

		$results=$this->mycurl->post($url,$params);
		if($results['err_code']=='0')
			return $results['data']['items'];
	}

	function get_template_name_by_id($template_id)
	{
		$url="/rev_template/list/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'template_id'=>$template_id
		);

		$results=$this->mycurl->post($url,$params);

		if($results['err_code']=='0')
			return $results['data']['items'][0]['template_name'];
	}

	function update_template_name_by_id($template_id,$template_name)
	{
		$url="/rev_template/update/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'template_id'=>$template_id,
			'template_name'=>$template_name
		);

		$results=$this->mycurl->post($url,$params);

		if($results['err_code']=='0')
			return $results['data'][0];
	}
	
	function delete_template_by_id($template_id)
	{
		$url="/rev_template/remove/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'template_id'=>$template_id
		);

		$results=$this->mycurl->post($url,$params);
		
		if($results['err_code']=='0')
			return $results['data'];
	}

	function add_template_node($template_id,$node_name,$node_description,$node_type,$score,$content_restrict)
	{
		$url="/rev_template_node/insert/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'template_id'=>$template_id,
			'node_name'=>$node_name,
			'node_description'=>$node_description,
			'node_type'=>$node_type,
			'score'=>$score,
			'content_restrict'=>$content_restrict
		);

		$results=$this->mycurl->post($url,$params);
		
		if($results['err_code']=='0')
			return $results['data'];
	}

	function get_template_all_nodes($template_id)
	{
		$url="/rev_template_node/list/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'template_id'=>$template_id
		);

		$results=$this->mycurl->post($url,$params);
		
		if($results['err_code']=='0')
			return $results['data']['items'];
	}


	function get_template_node_by_id($node_id)
	{
		$url="/rev_template_node/list/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'node_id'=>$node_id
		);

		$results=$this->mycurl->post($url,$params);
		
		if($results['err_code']=='0')
			return $results['data']['items'][0];
	}

	function update_template_node($node_id,$template_id,$node_name,$node_description,$node_type,$score,$content_restrict)
	{
		$url="/rev_template_node/update/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'node_id'=>$node_id,
			'template_id'=>$template_id,
			'node_name'=>$node_name,
			'node_description'=>$node_description,
			'node_type'=>$node_type,
			'score'=>$score,
			'content_restrict'=>$content_restrict
		);

		$results=$this->mycurl->post($url,$params);
		
		if($results['err_code']=='0')
			return $results['data'];
	}


	function update_template_node_active($node_id,$active)
	{
		$url="/rev_template_node/update/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'node_id'=>$node_id,
			'active'=>$active	
		);

		$results=$this->mycurl->post($url,$params);
		
		if($results['err_code']=='0')
			return $results['data'];
	}

	function delete_template_node($node_id)
	{
		$url="/rev_template_node/remove/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'node_id'=>$node_id	
		);

		$results=$this->mycurl->post($url,$params);
		
		if($results['err_code']=='0')
			return $results['data'];
	}
	

	function get_teacher_review_detail($tid)
	{
		$url="/rev_expert_group_re/expert_review/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'teacher_id'=>$tid	
		);

		$results=$this->mycurl->post($url,$params);
		
		if($results['err_code']=='0')
			return $results['data'];
	}

	function get_projects_with_group_id($group_id)
	{
		$url="/qlty_project/group/";

		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'group_id'=>$group_id	
		);

		$results=$this->mycurl->post($url,$params);

		if($results['err_code']=='0')
			return $results['data'];

	}

	
	function update_rev_results($project_id,$expert_id,$review_id,$rev_result_array)
	{
		$url="/rev_result/replace/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'qlty_project_id'=>$project_id,
			'expert_id'=>$expert_id,
			'review_id'=>$review_id,
			'rev_result_array'=>$rev_result_array
		);

		$results=$this->mycurl->post($url,$params);
		if($results['err_code']=='0')
			return $results['data'];
	}

	function get_rev_results($project_id,$current_expert_id,$review_id)
	{
		$url="/rev_result/list/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'qlty_project_id'=>$project_id,
			'expert_id'=>$current_expert_id,
			'review_id'=>$review_id
		);

		$results=$this->mycurl->post($url,$params);

		if($results['err_code']=='0')
			return $results['data']['items'];
	}

	function get_rev_results_detail($review_id)
	{
		$url="/rev_result/result_detail/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'review_id'=>$review_id
		);
	
		$results=$this->mycurl->post($url,$params);

		if($results['err_code']=='0')
			return $results['data'];

	}

	function get_rev_results_detail_with_expert_id($review_id,$expert_id)
	{
		$url="/rev_result/expert_result_detail/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'review_id'=>$review_id,
			'expert_id'=>$expert_id
		);
	
		$results=$this->mycurl->post($url,$params);
		
		if($results['err_code']=='0')
			return $results['data'];

	}

	function get_all_teachers_detail()
	{
		$url="/odp_teacher/all/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token
		);
	
		$results=$this->mycurl->post($url,$params);

		if($results['err_code']=='0')
			return $results['data'];
	}

	function get_review_id_by_project_id($qlty_project_id)
	{
		$url="/rev_project_group_re/reviewid/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'qlty_project_id'=>$qlty_project_id
		);
	
		$results=$this->mycurl->post($url,$params);

		if($results['err_code']=='0')
			return $results['data'];
	}

	function email_set_pwd($newpwd,$teacher_id,$access_token)
	{
		$url="odp_teacher/update/";
		$params = Array(
			'access_token'=>$access_token,
			'teacher_pwd'=>md5($newpwd),
			'teacher_id'=>$teacher_id
		);
		$results = $this->mycurl->post($url,$params);

		if($results['err_code']=='0')
			return $results['data'][0]['teacher_id'];

	}

	function update_last_login_time($teacher_id)
	{
		$url="odp_teacher/update/";
		$access_token =  self::refresh_client_access_token();
		$params = Array(
			'access_token'=>$access_token,
			'teacher_id'=>$teacher_id,
			'last_login_time'=>time()
		);
		$results = $this->mycurl->post($url,$params);

		if($results['err_code']=='0')
			return $results['data'][0]['teacher_id'];
	}

	function get_project_funds($teacher_id)
	{
		//主持人项目
		$url = "qlty_funds/funds/";
		$access_token =  self::get_user_access_token();
		$params = Array(
			'access_token'=>$access_token,
			'teacher_id'=>$teacher_id
		);
		$results = $this->mycurl->post($url,$params);
		//print_r($results);
		if($results['err_code']=='0')
			return $results['data'];
	}

	function get_participant_project_funds($teacher_id)
	{
		$url = "qlty_funds/participant_funds/";
		$access_token =  self::get_user_access_token();
		$params = Array(
			'access_token'=>$access_token,
			'teacher_id'=>$teacher_id
		);
		$results = $this->mycurl->post($url,$params);
		//print_r($results);
		if($results['err_code']=='0')
			return $results['data'];
	}

	function get_unfinished_participant_projects($teacher_id)
	{
		$url = "qlty_participant/unfinished_projects/";
		$access_token =  self::get_user_access_token();
		$params = Array(
			'access_token'=>$access_token,
			'teacher_id'=>$teacher_id
		);
		$results = $this->mycurl->post($url,$params);
		//print_r($results);
		if($results['err_code']=='0')
			return $results['data'];
	}

	function get_project_sum_fund($project_id)
	{
		$url="qlty_funds/project_fund/";
		//check qrcode ,use client access token
		$access_token = self::refresh_client_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'project_id'=>$project_id
			);
		$results=$this->mycurl->post($url,$params);
		//print_r($results);
		if($results['err_code']=='0')
			return $results['data'];
	}

	function get_project_apply_sum_fund($project_id)
	{
		$url="qlty_funds/project_apply_fund/";
		//check qrcode ,use client access token
		$access_token = self::refresh_client_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'project_id'=>$project_id
			);
		$results=$this->mycurl->post($url,$params);
		//print_r($results);
		if($results['err_code']=='0')
			return $results['data'];
	}

	function add_project_fund_record($params)
	{
		$url="qlty_funds/insert/";
		$access_token=self::get_user_access_token();
		$params = $params + Array('access_token'=>$access_token);

		$results=$this->mycurl->post($url,$params);

		if($results['err_code']=='0')
			return $results['data'][0];
	}

	function get_fund_record_detail($fundid)
	{
		$url="qlty_funds/list/";
		//check qrcode need use this api, so client access token
		$access_token=self::refresh_client_access_token();
		$params=Array(
			'fund_id'=>$fundid,
			'access_token'=>$access_token
			);
		$results=$this->mycurl->post($url,$params);

		if($results['err_code']=='0')
			return $results['data']['items'];

	}

	function get_fund_records($count)
	{
		$url="qlty_funds/list/";
		//check qrcode need use this api, so client access token
		$access_token=self::refresh_client_access_token();
		$params=Array(
			'count'=>$count,
			'access_token'=>$access_token
			);
		$results=$this->mycurl->post($url,$params);

		if($results['err_code']=='0')
			return $results['data']['items'];

	}

	function update_fund_ticket_url($fundid,$ticket_url)
	{
		$url="qlty_funds/update/";
		$access_token=self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'fund_id'=>$fundid,
			'ticket_url'=>$ticket_url
			);
		$results = $this->mycurl->post($url,$params);

		if($results['err_code']=='0')
			return $results['data'][0];
	}

	function get_fund_records_teacher_with_project_id($project_id)
	{
		$url="qlty_funds/fund_records_detail/";
		$access_token=self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'qlty_project_id'=>$project_id
			);
		$results=$this->mycurl->post($url,$params);

		if($results['err_code']=='0')
			return $results['data'];
	}

	function get_teacher_info_with_id($teacher_id)
	{
		$url="odp_teacher/list/";
		$access_token=self::refresh_client_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'teacher_id'=>$teacher_id
			);
		$results=$this->mycurl->post($url,$params);

		if($results['err_code']=='0')
			return $results['data']['items'][0];
	}

	function get_all_teacher_info()
	{
		$url="odp_teacher/list/";
		$access_token=self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token
			);
		$results=$this->mycurl->post($url,$params);

		if($results['err_code']=='0')
			return $results['data']['items'];
	}

	function get_unsign_fund_with_project_id($project_id)
	{
		//去除了不同意的项目，查询director_checked不等于2，sign=0的项目
		$url="qlty_funds/unsign_fund/";
		$access_token=self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'qlty_project_id'=>$project_id
			);
		$results=$this->mycurl->post($url,$params);

		if($results['err_code']=='0')
			return $results['data'];
	}

	function update_fund_sign_status($fund_id,$sign_comment,$sign_tid)
	{
		$url="qlty_funds/update/";
		$access_token=self::refresh_client_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'fund_id'=>$fund_id,
			'sign'=>1,
			'sign_time'=>time(),
			'sign_tid'=>$sign_tid,
			'sign_comment'=>$sign_comment
			);
		$results=$this->mycurl->post($url,$params);
		if($results['err_code']=='0')
			return $results['data'][0];
	}

	function get_fund_unchecked_by_direcotr($qlty_project_id)
	{
		$url="qlty_funds/unchecked_fund/";
		$access_token=self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'qlty_project_id'=>$qlty_project_id
			);
		$results=$this->mycurl->post($url,$params);
		if($results['err_code']=='0')
			return $results['data'];
	}

	function update_director_checked($fund_id,$director_checked)
	{
		$url="qlty_funds/update/";
		$access_token=self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'fund_id'=>$fund_id,
			'director_checked'=>$director_checked
			);
		$results=$this->mycurl->post($url,$params);

		if($results['err_code']=='0')
			return $results['data'][0];
	}

	function get_teachers_by_name($teacher_name)
	{
		$url="odp_teacher/teacher_name/";
		$params=Array();
		$params['teacher_name']=$teacher_name;
		$params['access_token']=self::refresh_client_access_token();
		$results=$this->mycurl->post($url,$params);
		if($results['err_code']=='0')
			return $results['data'];
	}

	function get_teacher_pwd_null($code)
	{
		$url="odp_teacher/null_pwd/";
		$access_token=self::refresh_client_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'code'=>$code
			);
		$results=$this->mycurl->post($url,$params);

		if($results['err_code']=='0')
			return $results['data'];
	}

	function init_pwd($newpwd,$code)
	{
		$url="odp_teacher/init_pwd/";
		$access_token=self::refresh_client_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'newpwd'=>$newpwd,
			'code'=>$code
			);
		$results=$this->mycurl->post($url,$params);
		if($results['err_code']=='0')
			return $results['data'];
	}

	function get_all_projects_detail()
	{
		$url="odp_teacher/get_all_projects_detail/";
		$access_token=self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token
			);
		$results=$this->mycurl->post($url,$params);
		if($results['err_code']=='0')
			return $results['data'];
	}

	function get_less_than_the_status_projects($status)
	{
		$url="qlty_project/less_than_status/";
		$access_token = self::get_user_access_token();
		$params=Array(
			'access_token'=>$access_token,
			'status'=>$status
		);
		$results=$this->mycurl->post($url,$params);
		if($results['err_code']=='0')
			return $results['data'];
	}

	function update_teacher_info($teacher_id,$is_inside_school,$department_id,$staff_id,$professional_title,$mobile_phone)
	{
		$url="odp_teacher/update/";
		$access_token=self::get_user_access_token();
		$params=Array(
				'access_token'=>$access_token,
				'teacher_id'=>$teacher_id,
				'is_inside_school'=>$is_inside_school,
				'department_id'=>$department_id,
				'staff_id'=>$staff_id,
				'professional_title'=>$professional_title,
				'mobile_phone'=>$mobile_phone
			);
		$results=$this->mycurl->post($url,$params);
		if($results['err_code']=='0')
			return $results['data'][0];
	}

	function update_project_attr($params)
	{
		$url="qlty_project/update/";
		$access_token=self::get_user_access_token();
		$params = $params + Array('access_token'=>$access_token);
		$result = $this->mycurl->post($url,$params);
		if($result['err_code']=='0')
			return $result['data'][0];

	}

	function get_project_review_suggestion($project_id,$review_id,$group_id)
	{
		$url="rev_result/suggestion/";
		$access_token=self::get_user_access_token();
		$params = array(
			'access_token'=>$access_token,
			'project_id'=>$project_id,
			'review_id'=>$review_id,
			'group_id'=>$group_id
			);
		$result = $this->mycurl->post($url,$params);
		if($result['err_code']=='0')
			return $result['data'];

	}
}